# !/usr/bin/env python
# encoding: utf-8


"""
  @author: gaogao
  @file: wafer.py
  @time: 2022/6/13 17:28
  @desc:
"""

from sqlalchemy import Column, Integer, String, DateTime
from sqlalchemy import ForeignKey
from sqlalchemy.dialects.mysql import MEDIUMTEXT
from sqlalchemy.dialects.mysql import LONGTEXT
from database.base import Base
import datetime
from database.base_model import BaseModel
from sqlalchemy.orm import relationship


class Chip(Base.base, BaseModel):
    # 指定本类映射到diode表
    __tablename__ = 'chip'
    # 指定id映射到id字段; id字段为整型，为主键,自增
    id = Column(Integer, primary_key=True, autoincrement=True)
    chip_name = Column(String(50))
    # wafer_name
    wafer_name = Column(String(50), ForeignKey("wafer.wafer_name", ondelete="SET NULL"))
    wafer = relationship("Wafer", back_populates="chip")
    # x、y
    shot_position = Column(String(10))
    # shot编号
    shot_number = Column(String(10))
    # chip编号
    chip_number = Column(String(20))

    # polarization_type
    polarization_type = Column(String(5))
    measurement_parameter = Column(String(50))
    # measurement_data
    measurement_data = Column(LONGTEXT())
    # data_unit
    data_unit = Column(String(10))
    # data_type
    data_type = Column(String(5))
    # 测试时间
    measurement_time = Column(DateTime, default=datetime.datetime.now())

    def __init__(self, chip_name, wafer_name, shot_position, shot_number, chip_number, polarization_type,
                 measurement_parameter,
                 measurement_data, data_unit, data_type,measurement_time):
        self.chip_name = chip_name
        self.wafer_name = wafer_name
        self.shot_position = shot_position
        self.shot_number = shot_number
        self.chip_number = chip_number
        self.polarization_type = polarization_type
        self.measurement_parameter = measurement_parameter
        self.measurement_data = measurement_data
        self.data_unit = data_unit
        self.data_type = data_type
        self.measurement_time = measurement_time

    def __repr__(self):
        return "<Chip(chip_name='%s', wafer_name='%s')>" % (self.chip_name, self.wafer_name)
